$(document).ready(function(){

	$.ajax({
  		type: "post",
 		url: "hmk/getWukuType_getWukuType.action",
  		success:function(data){
  			$.each(data.typeList,function(i,n){
  				$("<option value="+n.tpyeId+">"+n.tpyeName+"</option>").appendTo('#wukutype_id');
			});
			
			//设置选中的select 			
			var type = $("#typeID").text();
			$("#wukutype_id option").each(function(){
				var v = $(this).attr("value");
				if(v==type){
					$(this).attr("selected","selected");
				}
			});
  		}
	});
	
	
	/////////////////////
	$("#acceptForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
            //form.submit();   //提交表单
          var teamID=$("#teamID").text();
		var typeID=$('#wukutype_id option:selected').val();
		var teamname=$('#teamName_ID').val();
		var teamscale=$('#teamscale_ID').val();
		var teamContact=$('#teamContact_ID').val();
		var teamTel=$('#teamTel_ID').val();
		var teamLocation=$('#teamLocation_ID').val();
		var teamDepart=$('#teamDepart_ID').val();
		var teamDuty=$('#teamDuty_ID').val();
			
			 $.ajax({
  			type: "post",
 			url: "hmk/saveTeam_updateTeam.action",
 			data:{
 				  teamID1:teamID,teamName1:teamname,teamDuty1:teamDuty,typeID:typeID,teamContact1:teamContact,
 				  teamDepart1:teamDepart,teamLocation1:teamLocation,teamScale1:teamscale,teamTel1:teamTel
 				 },
  			success:showData
		 });
		  
        },
		rules: {
			'wukutype_id':'required',
			'teamName_ID':'required',
			'teamDepart_ID':'required',
			'teamDuty_ID':'required',
			'teamLocation_ID':'required',
			'teamscale_ID':{
				required:true,
				digits:true
			}
			
		} ,
		messages: {
			'wukutype_id':"*必须选",
			'teamName_ID':"*必须选",
			'teamDepart_ID':"*必须选",
			'teamDuty_ID':"*必须选",
			'teamLocation_ID':'*必须选',
			'teamscale_ID':{
				required:'*必须选',
				digits:'数字'
			}
			
		}
	});
	//////////////////////
	
	/*
	//提交更新（team救援队伍）
	$('#ADD_TEAM').click(function(){
		var teamID=$("#teamID").text();
		var typeID=$('#wukutype_id option:selected').val();
		var teamname=$('#teamName_ID').val();
		var teamscale=$('#teamscale_ID').val();
		var teamContact=$('#teamContact_ID').val();
		var teamTel=$('#teamTel_ID').val();
		var teamLocation=$('#teamLocation_ID').val();
		var teamDepart=$('#teamDepart_ID').val();
		var teamDuty=$('#teamDuty_ID').val();
		
		if(teamID!==null && teamID.length!==0 && typeID!==null && typeID.length!==0 && teamname!==null &&  teamname.length!==0 && 
		   teamscale!==null && teamscale.length!==0 && teamLocation!==null && teamLocation.length!==0 &&
		   teamDepart!==null && teamDepart.length!==0 && teamDuty!==null && teamDuty.length!==0 ){
			
		 $.ajax({
  			type: "post",
 			url: "hmk/saveTeam_updateTeam.action",
 			data:{
 				  teamID1:teamID,teamName1:teamname,teamDuty1:teamDuty,typeID:typeID,teamContact1:teamContact,
 				  teamDepart1:teamDepart,teamLocation1:teamLocation,teamScale1:teamscale,teamTel1:teamTel
 				 },
  			success:showData
		 });
		}else{
			alert("带*号的必填！");
		}
	});
	*/

	//返回操作
	$("#editteamBack").click(function(){
		var teamID=$("#teamID").text();
		window.location.href="/ag/hmk/findOneTeam_getOneTeam.action?teamID="+teamID+"&findType1=1";
	});
		
});
	
function showData(data){
		if(data.ajaxRST=='1'){
			alert("队伍更新成功");
			var teamID=$("#teamID").text();
			window.location.href="/ag/hmk/findOneTeam_getOneTeam.action?teamID="+teamID+"&findType1=1";
		}else{
			alert("队伍更新失败");
		}
}

